{extend name="common/index"}
{block name="css"}
<link rel="stylesheet" href="__STATIC__/plugins/web_font/jquery.cxcolor-1.2/css/jquery.cxcolor.css">
<style>
    .font-set {margin-top: 5px;}
    .font-set select{height: 22px;}

     {empty name="data.img_url"}
    .image-url .image-preview {display: none;}/*隐藏图片*/
    {else/}
    .image-url .image-text {display: none;}/*隐藏文字*/
    {/empty}
</style>
{/block}
{block name="content"}
<div class="layui-row">
    <form id="editForm" class="layui-form tpl-form-label-long" action="">
        <input type="hidden" name="banner_id" id="banner_id" value="{$data.banner_id|default=''}">
        <div class="layui-field-box">
            <div class="layui-main">
                <div class="layui-form-item">
                    <label class="layui-form-label">图片：<br>(1000*315)</label>
                    <div class="layui-input-block image-url">
                        <div class="layui-upload-drag">
                            <div class="image-text">
                                <i class="layui-icon layui-icon-upload"></i>
                                <p>点击上传，或将文件拖拽到此处</p>
                            </div>
                            <div class="image-preview">
                                <input type="hidden" name="img_url" value="{$data.img_url|default=''}" data-id="{$data.banner_id|default=''}" data-table="basic_banner">
                                <img src="{$data.img_url|default=''}" alt="图片">
                                <div class="tools tools-bottom">
                                    <a href="javascript:void(0);" onclick="delImgAjax(this);">
                                        <i class="layui-icon layui-icon-delete"></i>
                                    </a>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">名称：</label>
                    <div class="layui-input-block">
                        <input type="text" id="font_sample" name="img_name" value="{$data.img_name|default=''}" lay-verify="required" class="layui-input" style="{$data.img_name_style|default=''}"/>
                        <input type="hidden" name="img_name_style" value="{$data.img_name_style|default=''}">
                        <div class="font-set">
                            <select id="font_list" lay-ignore></select>
                            <select id="font_size_select" lay-ignore></select>
                            <input id="font_bold" type="checkbox" lay-ignore>粗体
                            <input id="font_italic" type="checkbox" lay-ignore>斜体
                            <input id="font_color" type="text" class="input_cxcolor" readonly="">
                        </div>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">链接：</label>
                    <div class="layui-input-block">
                        <input type="text" name="link" value="{$data.link|default=''}" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">banner位置：</label>
                    <div class="layui-input-block">
                        {volist name="locationList" id="vo"}
                        <input type="radio" name="location" value="{$vo.basic_id}" title="{$vo.basic_name}" {eq name="vo.basic_id" value="$data.location|default='175'" }checked{/eq}>
                        {/volist}
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">是否显示：</label>
                    <div class="layui-input-block">
                        <input type="radio" name="state" value="1" title="是" {eq name="data.state|default='1'" value="1" }checked{/eq}>
                        <input type="radio" name="state" value="0" title="否" {eq name="data.state|default='1'" value="0" }checked{/eq}>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">文字内容：</label>
                    <div class="layui-input-block">
                        <!-- 加载编辑器的容器 -->
                        <script id="editor-describe" name="describe" type="text/html">{$data.describe|default=''}</script>
                    </div>
                </div>
            </div>
            <div class="tpl-form-action">
                <button class="layui-btn layui-btn-radius layui-btn-lg" lay-submit lay-filter="formSubmit">保存</button>
            </div>
        </div>
    </form>
</div>
{/block}

{block name="script"}
<script type="text/javascript" src="__STATIC__/plugins/ueditor/ueditor.config.js"></script><!-- 编辑器配置文件 -->
<script type="text/javascript" src="__STATIC__/plugins/ueditor/ueditor.all.min.js"></script><!-- 编辑器源码文件 -->
<script type="text/javascript" src="__STATIC__/plugins/web_font/jquery.cxcolor-1.2/jquery.cxcolor.js"></script>
<script type="text/javascript" src="__STATIC__/plugins/web_font/swfobject-2.2.min.js"></script>
<script type="text/javascript" src="__STATIC__/plugins/web_font/init.js"></script>

<script type="text/javascript">
    layui.use(['form', 'laydate'], function () {
        var form = layui.form;

        //上传图片
        uploadImgAjax('.image-url', '{:url("uploadImg")}', 4096);

        //监听提交
        form.on('submit(formSubmit)', function(data){
            var index = layer.load(2, {shade:[0.5,'#000'],time: 10*1000});
            var dom_from = $('#editForm');
            var name_style = dom_from.find('input[name="img_name"]').attr('style');
            dom_from.find('input[name="img_name_style"]').val(name_style);
            $.post('{:url("save")}', dom_from.serialize(), function (result) {
                layer.close(index);
                if (result.code) {
                    layer.msg(result.msg, {shade:[0.5,'#000'],time:1000}, function () {
                        window.location.href = result.url;
                    });
                } else {
                    layer.alert(result.msg, {icon:2, title:'保存失败！'});
                }
            }, 'json');
            return false;
        });
    });

    //实例化编辑器*
    UE.getEditor('editor-describe');
</script>
{/block}